home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / news / nntp / nntp.1.5.11 / server / group.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-04  |  2.3 KB  |  111 lines

  1. #ifndef lint
  2. static char    *sccsid = "@(#)group.c    1.12    (Berkeley) 5/11/89";
  3. #endif
  4.  
  5. #include "common.h"
  6.  
  7. /*
  8.  * GROUP newsgroup
  9.  *
  10.  * Change the current group to the specified newsgroup.
  11.  * We also change our current directory to that newsgroup if
  12.  * a spool directory for it exists.
  13.  * If the newsgroup specified is invalid, the old newsgroup
  14.  * remains selected.
  15.  */
  16.  
  17. group(argc, argv)
  18.     int    argc;
  19.     char    *argv[];
  20. {
  21.     char    temp_dir[256];
  22.     int    high_msg, low_msg;
  23.     char    *cp;
  24.     char    *reqlist[2];
  25.  
  26.     if (argc != 2) {
  27.         printf("%d Usage: GROUP newsgroup.\r\n", ERR_CMDSYN);
  28.         (void) fflush(stdout);
  29.         return;
  30.     }
  31.  
  32.     if (!canread) {
  33.         printf("%d You only have permission to transfer, sorry.\r\n",
  34.             ERR_ACCESS);
  35.         (void) fflush(stdout);
  36.         return;
  37.     }
  38.  
  39.     if (index(argv[1], '/') != (char *) NULL) {
  40.         printf("%d Invalid group name (bad format).\r\n", ERR_NOGROUP);
  41.         (void) fflush(stdout);
  42.         return;
  43.     }
  44.  
  45.     if (find_group(argv[1], num_groups, &low_msg, &high_msg) < 0) {
  46.         printf("%d Invalid group name (not in active).\r\n",
  47.             ERR_NOGROUP);
  48.         (void) fflush(stdout);
  49.         return;
  50.     }
  51.  
  52.     reqlist[0] = argv[1];
  53.     reqlist[1] = NULL;
  54.  
  55.     if (ngpermcount) {
  56.         if (ngmatch(s1strneql, ALLBUT,
  57.             ngpermlist, ngpermcount, reqlist, 1) == 0) {
  58.             printf("%d You're not allowed to read %s, sorry.\r\n",
  59.                 ERR_ACCESS, argv[1]);
  60.             (void) fflush(stdout);
  61.             return;
  62.         }
  63.     } else if (ALLBUT == 0) {
  64.         printf("%d You're not allowed to read %s, sorry.\r\n",
  65.             ERR_ACCESS, argv[1]);
  66.         (void) fflush(stdout);
  67.         return;
  68.     }
  69.  
  70.     close_crnt();
  71.     (void) chdir(spooldir);
  72.  
  73. #ifdef LOG
  74.     syslog(LOG_INFO, "%s group %s", hostname, argv[1]);
  75. #endif
  76.  
  77.     while ((cp = index(argv[1], '.')) != (char *) NULL)
  78.         *cp = '/';
  79.  
  80.     (void) strcpy(temp_dir, spooldir);
  81.     (void) strcat(temp_dir, "/");
  82.     (void) strcat(temp_dir, argv[1]);
  83.  
  84.     /*
  85.      * (void) because a group can be in the active file
  86.      * but not have a spool directory.  Just leave us
  87.      * chdired to base spool directory if this fails.
  88.      */
  89.     (void) chdir(temp_dir);
  90.  
  91. #ifdef LOG
  92.     ++grps_acsd;
  93. #endif
  94.  
  95.     num_arts = scan_dir(low_msg, high_msg);
  96.     art_ptr = 0;
  97.  
  98.     ingroup = 1;
  99.  
  100.     while ((cp = index(argv[1], '/')) != (char *) NULL)
  101.         *cp = '.';
  102.  
  103.     printf("%d %d %d %d %s\r\n",
  104.         OK_GROUP,
  105.         num_arts,
  106.         (num_arts > 0 ? art_array[0] : 0),
  107.         (num_arts > 0 ? art_array[num_arts-1] : 0),
  108.         argv[1]);
  109.     (void) fflush(stdout);
  110. }
  111.